package com.s63.springboot3.config;

import com.s63.springboot3.entity.User;
import com.s63.springboot3.mapper.RoleMapper;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        System.out.println("上下文监听器启动了，初始化一些资源");
        // 缓存角色列表
        List<User> list = roleMapper.getAll();
        CacheManager.put("roleList", list);
    }
}
